
import React, { ComponentType } from 'react';
import styles from './index.module.less';
import { Spin } from '@/components/base';

/** 懒加载 */
export function lazy<T extends ComponentType>(load: () => Promise<{ default: T }>, loading?: React.ReactNode): React.FC<any> {
    const Com = React.lazy(load);
    return (props: any) => {
        return (
            <React.Suspense fallback={loading || <Spin wrapperClassName={styles.loading} tip="加载中..." ><div /></Spin>}>
                <Com {...props} />
            </React.Suspense>
        )
    };
}

